
const state = {
	cartList: JSON.parse(uni.getStorageSync('cartList') || '[]')
}
const mutations = {
	updateCartList(state, cartItem) {
		console.warn('cartItem', cartItem)
		let flag = false
		state.cartList.forEach((key, i) => {
			if (key.id == cartItem.id) {
				flag = true
				return
			}
		})
		if (!flag) {
			cartItem.isClick = false
			state.cartList.push(cartItem)
			uni.setStorageSync('cartList', JSON.stringify(state.cartList))
			console.warn('执行完了')
			uni.$toast('加入购物车成功')
		}else {
			uni.$toast('已加入购物车')
		}
		
	},
	removeCartList(state, id) {
		id.forEach((item2, i) => {
			state.cartList.forEach((item3, i3) => {
				if (item2 == item3.id) {
					state.cartList.splice(i3, 1)
				}
			})
		})
		uni.setStorageSync('cartList', JSON.stringify(state.cartList))
	}
}
export default {
	namespaced: true,
	state,
	mutations
}